﻿using System;

namespace c2
{
    public delegate void tickHandler(object sender, tickEventArgs e);
    public delegate void alarmHandler(object sender, alarmEventArgs e);
    public class alarmEventArgs
    {
        /*public alarmEventArgs()
        {
            Console.WriteLine("叮铃铃，时间到了！");
        }*/
    }
    public class tickEventArgs
    {
        //public int time { get; set; }
        //public tickEventArgs()
        //{
        //    Console.WriteLine("嘀嗒");
            
        //}
    }
    public class Clock
    {
        public event tickHandler clockTick;
        public event alarmHandler clockAlarm;
        public int time;
        public void setClock(int t)
        {
            this.time = t;
            if (t >= 0)
            {
                int i = 0;
                while (i < t)
                {
                    System.Threading.Thread.Sleep(1000);
                    tickEventArgs args = new tickEventArgs();
                    clockTick(this, args);
                    i++;
                }
                alarmEventArgs args1 = new alarmEventArgs();
                clockAlarm(this, args1);

            }
            else
            {
                Console.WriteLine("错误");
            }
        }

    }
    class Program
    {
        static void showTick(object sender, tickEventArgs e)
        {
            Console.WriteLine("嘀嗒");
        }
        static void showAlarm(object sender,alarmEventArgs e)
        {
            Console.WriteLine("叮铃铃，时间到了！");
        }
        static void Main(string[] args)
        {
            var clock = new Clock();
            clock.clockTick += showTick;
            clock.clockAlarm += showAlarm;
            Console.WriteLine("设置闹钟，倒计时（秒）:");
            string ts = Console.ReadLine();
            int t = Convert.ToInt32(ts);
            clock.setClock(t);
        }
    }
}
